;(function (window, angular) {
    'use strict';
    angular.module("Filter.All", [])
        .filter("ApiUrl", ['ybConfig', function (ybConfig) {
            return function (url) {
                return ybConfig.getConfig().baseUrl.Site + url;
            };
        }])

        .filter("YbDate", ['$filter', function ($filter) {
            return function (val, format) {
                if (!val) {
                    return "";
                }
                if (!format) {
                    format = "yyyy-MM-dd";
                }

                var result = $filter("date")(val, format);
                return result;
            }
        }])

        .filter("YbWeek", ['$filter', function ($filter) {
            return function (val, format) {
                if (!val) {
                    return "";
                }
                var date = new Date(val);
                var weekday = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
                var result = weekday[date.getDay()];
                return result;
            }
        }])

        .filter("TrueOrFalse", ['$filter', function ($filter) {
            var filterMsg = {
                normal: ["否", "是"],
                sex: ["女", "男"],
                lockStatues: ["启用", "锁定"],
                inOut: ["入库类型", "出库类型"]
            };
            var type = "";
            return function (val, param) {
                type = !!param ? param : "normal";
                switch (val) {
                    case 0:
                        return filterMsg[type][0];
                    case 1:
                        return filterMsg[type][1];
                    default:
                        return filterMsg[type][0];
                }
            }
        }])

        .filter("decimalPlaces", function () {
            return function (val, places) {
                // todo 完善小数保留位数
                var result = val.toFixed(places);
                return result;
            }
        })
        .filter("decimalCover", function () {
            return function (val, places) {
                var m = Math.pow(10, places);
                val = Math.round(val * m) / m;
                if (!val) {
                    return "";
                }
                var fillSeats = "";
                var valArr = val.toString().split(".");
                if (valArr.length == 1) {
                    fillSeats = ".";
                    for (var i = 0; i < places; i++) {
                        fillSeats += "0";
                    }
                    val = val.toString() + fillSeats;
                }

                if (valArr.length > 1 && valArr[1].length < m) {
                    for (var i = valArr[1].length; i < places; i++) {
                        fillSeats += "0";
                    }
                    val = val.toString() + fillSeats;
                }
                return val;
            }
        })
        .filter('ybTrustHtml', ['$sce', function ($sce) {
            return function (text) {
                return $sce.trustAsHtml(text);
            }
        }])

        .filter("TrueOrFalseOrNull", function () {
            return function (data) {
                var result = "-";
                switch (data) {
                    case 0:
                        result = "否";
                        break;
                    case 1:
                        result = "是";
                        break;
                    default:
                        break;
                }
                return result;
            }
        })

    ;
})(window, window.angular);
